package com.zrf.base.knowledge.proxy.dynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author zhouruifeng
 *         create at 2017/3/5.
 */
public class DynamicProxy implements InvocationHandler {
    /**
     * 用于接收具体实现类的实例对象
     */
    private Object object;

    public DynamicProxy(Object object) {
        this.object = object;
    }

    /**
     * 代理方法
     * @param proxy 代理
     * @param method  方法
     * @param args 参数
     * @return  null
     * @throws Throwable 异常
     */
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("动态代理前");

        method.invoke(object, args);

        System.out.println("动态代理后");
        return null;
    }
}
